import axios from "axios";
import config from "@/util/config.js";

//创建一个axios的对象
const workAPI = {
    mdBaseUrl: config.mdUrl+"/md",
    mdProMat: "/work",
    timeout: 5000,

    //分页查询工作站信息
    getWorks(param, callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/query", {
            params: param
        }).then((res) => {
            callback(res.data);
        })
    },
    //获取工作站总数
    getCount(callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/count").then((res) => {
            callback(res.data);
        })
    },
    //添加工作站信息
    addWork(param, callback) {
        axios.request({
            url: this.mdBaseUrl + this.mdProMat + "/add",
            method: "post",
            data: JSON.stringify(param),
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            }
        }).then((res) => {
            callback(res.data);
        })
    },
    //修改工作站信息
    updateWork(param, callback) {
        axios.request({
            url: this.mdBaseUrl + this.mdProMat + "/update",
            method: "put",
            data: JSON.stringify(param),
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            }
        }).then((res) => {
            callback(res.data);
        })
    },
    //删除工作站信息
    deleteWork(param, callback) {
        axios.request({
            url: this.mdBaseUrl + this.mdProMat + "/"+param.id,
            method: "delete",
        }).then((res) => {
            callback(res.data);
        })
    },
    //批量删除
    deleteWorks(param, callback) {
        axios.request({
            url: this.mdBaseUrl + this.mdProMat + "/del/mall",
            method: "delete",
            data: JSON.stringify(param),
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            }
        }).then((res) => {
            callback(res.data);
        })
    },
}
export default workAPI;